package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.bairong.BairongRiskRatingRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百融风险等级预测
 *
 * @author guoqiang
 */

public class BairongRiskRatingParse extends ParseBase {
    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百融风险等级预测
     *
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BairongRiskRatingRecord obj = (BairongRiskRatingRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful);

        StringBuilder TxSb = new StringBuilder(500);
        TxSb.append(formatValue(obj.getSwift_number())).append(CRT001);
        TxSb.append(formatValue(obj.getCode())).append(CRT001);
        TxSb.append(formatValue(obj.getFlag_riskrating())).append(CRT001);
        TxSb.append(formatValue(obj.getRr_fraud())).append(CRT001);
        TxSb.append(formatValue(obj.getRr_credit())).append(CRT001);
        TxSb.append(formatValue(obj.getFlag_datastrategy())).append(CRT001);
        TxSb.append(formatValue(obj.getStrategy_version())).append(CRT001);
        TxSb.append(formatValue(obj.getProduct_type())).append(CRT001);
        TxSb.append(formatValue(obj.getStrategy_id())).append(CRT001);
        TxSb.append(formatValue(obj.getProduct_name())).append(CRT001);
        TxSb.append(formatValue(obj.getScene())).append(CRT001);
        setFileNum(5);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getType() + getSubType());
        val.set((sb.toString() + TxSb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_bairong_risk_rating_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIRONG_RISK_RATING_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百融风险等级预测";
    }
}
